package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.system.domain.JiajiaOrderTime;
import com.ruoyi.system.domain.JiajiaWorkerTimeXxConfig;
import com.ruoyi.system.mapper.JiajiaOrderTimeMapper;
import com.ruoyi.system.mapper.JiajiaWorkerTimeXxConfigMapper;
import com.ruoyi.system.service.IJiajiaWorkerTimeXxConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 社工休息时间配置Service业务层处理
 * 
 * @author 郑鑫
 * @date 2024-04-24
 */
@Service
public class JiajiaWorkerTimeXxConfigServiceImpl implements IJiajiaWorkerTimeXxConfigService
{
    @Resource
    private JiajiaWorkerTimeXxConfigMapper jiajiaWorkerTimeXxConfigMapper;

    @Resource
    private JiajiaOrderTimeMapper jiajiaOrderTimeMapper;

    /**
     * 查询社工休息时间配置
     * 
     * @param id 社工休息时间配置主键
     * @return 社工休息时间配置
     */
    @Override
    public JiajiaWorkerTimeXxConfig selectJiajiaWorkerTimeXxConfigById(Long id)
    {
        return jiajiaWorkerTimeXxConfigMapper.selectJiajiaWorkerTimeXxConfigById(id);
    }

    /**
     * 查询社工休息时间配置列表
     * 
     * @param jiajiaWorkerTimeXxConfig 社工休息时间配置
     * @return 社工休息时间配置
     */
    @Override
    public List<JiajiaWorkerTimeXxConfig> selectJiajiaWorkerTimeXxConfigList(JiajiaWorkerTimeXxConfig jiajiaWorkerTimeXxConfig) {
        List<JiajiaWorkerTimeXxConfig> timeXxConfigs = jiajiaWorkerTimeXxConfigMapper.selectJiajiaWorkerTimeXxConfigList(jiajiaWorkerTimeXxConfig);
        List<JiajiaOrderTime> jiajiaOrderTimes=jiajiaOrderTimeMapper.selectJiajiaTimeList(jiajiaWorkerTimeXxConfig);
        for (JiajiaOrderTime jiajiaOrderTime:jiajiaOrderTimes) {
            JiajiaWorkerTimeXxConfig jiajiaWorkerTimeConfig=new JiajiaWorkerTimeXxConfig();
            jiajiaWorkerTimeConfig.setTcid(jiajiaOrderTime.getTcid());
            jiajiaWorkerTimeConfig.setDay(jiajiaOrderTime.getDay());
            jiajiaWorkerTimeConfig.setWid(jiajiaOrderTime.getWid());
            jiajiaWorkerTimeConfig.setStatus(0);
            timeXxConfigs.add(jiajiaWorkerTimeConfig);
        }
        return timeXxConfigs;
    }

    @Override
    public List<JiajiaWorkerTimeXxConfig> selectTimeXxConfigList(JiajiaWorkerTimeXxConfig jiajiaWorkerTimeXxConfig) {
        return jiajiaWorkerTimeXxConfigMapper.selectTimeXxConfigList(jiajiaWorkerTimeXxConfig);
    }

    /**
     * 新增社工休息时间配置
     * 
     * @param jiajiaWorkerTimeXxConfig 社工休息时间配置
     * @return 结果
     */
    @Override
    public int insertJiajiaWorkerTimeXxConfig(JiajiaWorkerTimeXxConfig jiajiaWorkerTimeXxConfig) {
        Integer status = jiajiaWorkerTimeXxConfig.getStatus();
        jiajiaWorkerTimeXxConfig.setStatus(null);
        List<JiajiaWorkerTimeXxConfig> list = jiajiaWorkerTimeXxConfigMapper.selectJiajiaWorkerTimeXxConfigList(jiajiaWorkerTimeXxConfig);
        if (list.isEmpty()){
            jiajiaWorkerTimeXxConfig.setStatus(0);
            return jiajiaWorkerTimeXxConfigMapper.insertJiajiaWorkerTimeXxConfig(jiajiaWorkerTimeXxConfig);
        }
        jiajiaWorkerTimeXxConfig.setStatus(status);
        return jiajiaWorkerTimeXxConfigMapper.update(jiajiaWorkerTimeXxConfig);
    }

    /**
     * 修改社工休息时间配置
     * 
     * @param jiajiaWorkerTimeXxConfig 社工休息时间配置
     * @return 结果
     */
    @Override
    public int updateJiajiaWorkerTimeXxConfig(JiajiaWorkerTimeXxConfig jiajiaWorkerTimeXxConfig)
    {
        return jiajiaWorkerTimeXxConfigMapper.updateJiajiaWorkerTimeXxConfig(jiajiaWorkerTimeXxConfig);
    }

    /**
     * 批量删除社工休息时间配置
     * 
     * @param ids 需要删除的社工休息时间配置主键
     * @return 结果
     */
    @Override
    public int deleteJiajiaWorkerTimeXxConfigByIds(String ids)
    {
        return jiajiaWorkerTimeXxConfigMapper.deleteJiajiaWorkerTimeXxConfigByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除社工休息时间配置信息
     * 
     * @param id 社工休息时间配置主键
     * @return 结果
     */
    @Override
    public int deleteJiajiaWorkerTimeXxConfigById(Long id)
    {
        return jiajiaWorkerTimeXxConfigMapper.deleteJiajiaWorkerTimeXxConfigById(id);
    }
}
